import { useEffect } from 'react';
import { useRouter } from 'next/router';

interface ProtectedRouteProps {
    children: React.ReactNode;
    requiredPermission: 'asker' | 'replyer';
}

const ProtectedRoute: React.FC<ProtectedRouteProps> = ({ children, requiredPermission }) => {
    const router = useRouter();
    
    useEffect(() => {
        const token = localStorage.getItem('token');
        const permission = localStorage.getItem('permission');
        
        if (!token || permission !== requiredPermission) {
            router.push('/login');
        }
    }, [router, requiredPermission]);

    return <>{children}</>;
};

export default ProtectedRoute; 